package com.shou.client;

import com.alipay.api.AlipayApiException;
import com.shou.api.model.dto.ParkingRecordDTO;
import com.shou.api.model.response.ResultData;
import com.shou.util.AliPayBean;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.shou.util.AliPayUtil;

@RestController
@CrossOrigin
@RequestMapping("/api/v1/pay")
public class PaymetController {
    @Resource
    AliPayUtil aliPayUtil;
    @PostMapping("/pay-parking-record")
    public ResultData<String> toAlipay(@RequestBody ParkingRecordDTO parkingRecordDTO) {

        // 封装沙箱支付宝支付信息
        AliPayBean alipayBean = new AliPayBean();
        alipayBean.setOut_trade_no(String.valueOf(parkingRecordDTO.getId()));
        alipayBean.setSubject("停车缴费管理系统");
        alipayBean.setTotal_amount(String.valueOf(parkingRecordDTO.getCost()));
        alipayBean.setBody("欢迎您在停车缴费管理系统上缴费！！");
        String pay = null;
        try {
            pay = aliPayUtil.pay(alipayBean);
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
        return ResultData.success(pay);
    }
}
